const jwt = require("jsonwebtoken");

let signkey = "jwt"; // 秘钥
// 生成token
const setToken = (username, pwd) => {
  const rule = {
    username,
    pwd: pwd
  }
  let ztoken = jwt.sign(rule, signkey, { expiresIn: 60 * 60 * 24 })
  return ztoken
};

//验证token
const verToken = async (token) => {
  await jwt.verify(token, signkey, (err, data) => {
    if (err) return false
    else return true
  })
};

module.exports = {
  setToken,
  verToken,
};
